<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="cf" uri="http://kyub.com/jsp/jstl/functions" %>
<%@ attribute name="pojoDescriptor" required="true" type="com.kyub.spring.gears.model.PojoDescriptor" %>
<%@ attribute name="gears_restfull_prefix" required="true" %>
<%@ attribute name="listDivName" required="true" %>
<%@ attribute name="dialogDivName" required="true" %>
<spring:message code="deleteConfirmationLabel" var="deleteConfirmationLabelVar" text="Sure ?"/>

<script type="text/javascript">


    function doSearch() {
        $("#${listDivName}").fadeOut("normal", function() {

            $("#${listDivName}").load('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/rialist', {_searchString : $('#_searchString').val() }, function(responseText, textStatus, XMLHttpRequest) {

                if (textStatus == 'error') {
                    $("#${listDivName}").html(responseText);
                }

                $("#${listDivName}").fadeIn('slow');


            });
        });
    }

    function doDelete(param) {


        if (confirm('${deleteConfirmationLabelVar}')) {
            $("#${listDivName}").fadeOut("slow", function() {
                $.get("${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/delete/" + param, function() {

                    $("#${listDivName}").load('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/rialist', {_searchString : $('#_searchString').val() }, function(responseText, textStatus, XMLHttpRequest) {

                        if (textStatus == 'error') {
                            $("#${listDivName}").html(responseText);
                        }

                        $("#${listDivName}").fadeIn('slow');


                    });
                });
            });
        }
    }


    function shiftPage(page) {
        $("#${listDivName}").fadeOut("slow", function() {

            $("#${listDivName}").load('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/rialist&LIST_PAGE_PARAM=' + page, {_searchString : $('#_searchString').val() }, function(responseText, textStatus, XMLHttpRequest) {
                $("#${listDivName}").fadeIn('slow');

            });
        });
    }


    function openDisplayDialog(urlParam) {
        $("#${dialogDivName}").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 576,
            width: 770,
            modal: true,
            title: '<spring:message code="${pojoDescriptor.name}.labelForm" text="Edit ${pojoDescriptor.name}"  htmlEscape="true"/>' });
        $("#${dialogDivName}").load(urlParam, function(responseText, textStatus, XMLHttpRequest) {

            if (textStatus == 'error') {
                $('#${dialogDivName}').html(responseText);
            }
            $('#${dialogDivName}').dialog('open');

        });
    }
</script>